package jhunter.dao.select;

public class Order {

	private boolean ascending;

	private boolean ignoreCase;

	private String propertyName;

	private String refName;

	public String toString() {
		return propertyName + ' ' + (ascending ? "asc" : "desc");
	}

	public Order ignoreCase() {
		ignoreCase = true;
		return this;
	}

	/**
	 * Constructor for Order.
	 */
	protected Order(String refName, String propertyName, boolean ascending) {
		this.propertyName = propertyName;
		this.ascending = ascending;
		this.refName = refName;
	}

	/**
	 * Ascending order
	 * 
	 * @param propertyName
	 * @return Order
	 */
	public static Order asc(String propertyName) {
		return new Order(null, propertyName, true);
	}

	public static Order asc(String refName, String propertyName) {
		return new Order(refName, propertyName, true);
	}

	/**
	 * Descending order
	 * 
	 * @param propertyName
	 * @return Order
	 */
	public static Order desc(String propertyName) {
		return new Order(null, propertyName, false);
	}

	public static Order desc(String refName, String propertyName) {
		return new Order(refName, propertyName, false);
	}

	public boolean isIgnoreCase() {
		return ignoreCase;
	}

	public String getPropertyName() {
		return propertyName;
	}

	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}

	public boolean isAscending() {
		return ascending;
	}

	public void setAscending(boolean ascending) {
		this.ascending = ascending;
	}

	public String getRefName() {
		return refName;
	}

	public void setRefName(String refName) {
		this.refName = refName;
	}

}
